import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Vector;

public class RNAFamily
{
	private String name;
	private Vector<RNASpecies> species;

	public RNAFamily(String name)
	{
		super();
		this.name = name;
		this.species = new Vector<RNASpecies>();
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public boolean add(RNASpecies e)
	{
		return species.add(e);
	}

	public RNASpecies searchSpecies(String nameOfSpecies)
	{
		for (int i = 0; i < size(); i++)
		{
			if (species.get(i).getName().compareTo(nameOfSpecies) == 0)
			{
				return species.get(i);
			}
		}
		return null;
	}

	// Ajout d'une structure a une espece
	public boolean addSpecies(String nameSpecies, RNASecondaryStructure rst)
	{
		RNASpecies s = searchSpecies(nameSpecies);
		if (s == null)
		{
			return add(new RNASpecies(nameSpecies))
					&& species.get(size() - 1).addSecondaryStructure(rst);
		} else
		{
			return s.addSecondaryStructure(rst);
		}
	}

	public RNASpecies get(int index)
	{
		return species.get(index);
	}

	public RNASpecies remove(int index)
	{
		return species.remove(index);
	}

	public int size()
	{
		return species.size();
	}

	public int SecondaryStructureSize()
	{
		int res = 0;
		for (int i = 0; i < species.size(); i++)
		{
			res += species.get(i).size();
		}
		return res;
	}

	public int statTrinucleotide(int[] tabStat, int relativePosition,
			int shift, int taille, boolean useX)
	{
		int sizet = 0;
		int tmp;
		for (int i = 0; i < size(); i++)
		{
			tmp = get(i).statTrinucleotide(tabStat, relativePosition, shift,
					taille, useX);
			sizet += tmp;
		}
		return sizet;
	}

	public void getMinMax(int[] min_max)
	{
		for (int i = 0; i < size(); i++)
		{
			get(i).getMinMax(min_max);
		}

	}

	public void writeData(BufferedWriter bw, int min, int max)
			throws IOException
	{
		for (int i = 0; i < size(); i++)
		{
			get(i).writeData(bw, name, min, max);
		}
	}

}
